﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizInterface.HR;
using DataInterface;
using Model;
using Base.Core.Biz;

namespace Biz.HR
{
    public class EmployeeService : IEmployeeService
    {
        //private static ILog logger = LogManager.GetLogger(typeof(EmployeeService));

        public IEmployeeRepository EmployeeRepository { get; set; }

        public IList<Employee> GetAllEmployees(IList<SearchInfo> searchInfos, PagingInfo pagingInfo, IList<OrderInfo> orders)
        {
            return EmployeeRepository.FindAll(searchInfos, pagingInfo, orders);
        }

        public Employee GetEmployee(int id)
        {
            return EmployeeRepository.Get(id);
        }

        public void SaveEmployee(Employee employee)
        {
            DoSave(employee);
        }

        private void DoSave(Employee employee)
        {
            EmployeeRepository.SaveOrUpdate(employee);
        }

        public void DeleteEmployee(int id)
        {
            DoDelete(id);
        }

        public void DeleteEmployees(IList<int> idList)
        {
            foreach (var id in idList)
            {
                DoDelete(id);
            }   
        }

        private void DoDelete(int id)
        {
            Employee employee = EmployeeRepository.Get(id);
            if (employee != null)
            {
                EmployeeRepository.Delete(employee);
            }
        }
    }
}
